﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Com.CMS263.BLL;
using Com.CMS263.PO;
using Com.CMS263.Util;

namespace Com.CMS263.Web.manage
{
    public partial class manage_job : System.Web.UI.Page
    {
        JobBLL bll = new JobBLL();
        public int type = 0;
        int pageSize = 10;
        int pageCount = 0;
        public int CurrentIndex
        {
            get { return Convert.ToInt32(ViewState["index"]); }
            set { ViewState["index"] = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!Page.IsPostBack)
            {
                BindData();
            }
        }
        public void BindData()
        {
            CurrentIndex = Convert.ToInt32(Request.QueryString.Get("page"));
            if (CurrentIndex == 0)
            {
                CurrentIndex = 1;
            }
            IList<Job> newslist = new List<Job>();
            newslist = bll.GetJobByTypeId(pageSize, CurrentIndex);
            pageCount = bll.GetTotal();
            GridView1.DataSource = newslist;
            GridView1.DataBind();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            int id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName.Equals("btnDel"))
            {
                try
                {
                    bll.DeleteJobById(id); ScriptManager.RegisterClientScriptBlock(this, GetType(), "js", "alert('删除成功')", true);
                }
                catch
                {

                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "js", "alert('删除失败')", true);
                }

                BindData();
            }
            else if (e.CommandName.Equals("btnEdit"))
            {
                Response.Redirect("add_job.aspx?id=" + id);
            }

        }
        public string GetPager()
        {

            return Pager.GetPager(pageCount, pageSize, CurrentIndex, type.ToString());
        }

     

    }
}
